package com.car.carmgr.service.impl;

import com.car.carmgr.bean.BaseStat;
import com.car.carmgr.bean.Customer;
import com.car.carmgr.mapper.CustomerMapper;
import com.car.carmgr.service.CustomerService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class CustomerServiceImpl implements CustomerService {

    @Autowired
    private CustomerMapper customerMapper;

    @Override
    public int insertCustomer(Customer customer) {
        return customerMapper.insertCustomer(customer);
    }

    @Override
    public int deleteCustomerById(Integer customerId) {
        return customerMapper.deleteCustomerById(customerId);
    }

    @Override
    public int updateCustomer(Customer customer) {
        return customerMapper.updateCustomer(customer);
    }

    @Override
    public PageInfo<Customer> findCustomerByWhere(String identity, String customerName, Integer sex, String address, String phone, String career, Date createTime, Integer page, Integer limit) {
        PageHelper.startPage(page,limit);
        List<Customer> list = customerMapper.findCustomerByWhere(identity, customerName, sex,  address,  phone,  career,  createTime);
        PageInfo<Customer> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public Integer getCountByWhere(String identity, String customerName, Integer sex, String address, String phone, String career, Date createTime) {
        return customerMapper.getCountByWhere(identity, customerName, sex,  address,  phone,  career,  createTime);
    }

    @Override
    public int deleteSomeCustomer(String[] split) {
        int row = 0;
        if(split != null && split.length != 0){

            for(String userId : split){
                row += customerMapper.deleteCustomerById(Integer.parseInt(userId));
            }
        }
        return row;
    }

    @Override
    public int findCustomerById(String identity) {
        return customerMapper.findCustomerById(identity);
    }

    @Override
    public List<BaseStat> getCountByAddress() {
        return customerMapper.getCountByAddress();
    }
}
